package com.example.shop_2305.minefg

import androidx.lifecycle.viewModelScope
import com.example.lib_base.entity.OrderEntity
import com.example.lib_base.entity.Res
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.SingleLiveData
import com.example.lib_base.param.PComment
import kotlinx.coroutines.launch

class OrderViewModel:BaseViewModel() {
    //请求订单列表
    val orderSuccess = SingleLiveData<Res<OrderEntity>>()
    val orderFail = SingleLiveData<String>()
    fun order(type:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                orderSuccess.postValue(apiService.order(type, limit, page))
            } catch (e: Exception) {
                orderFail.postValue(e.message.toString())
            }
        }
    }
    //发送评论
    val sendSuccess = SingleLiveData<Res<String?>>()
    val sendFail = SingleLiveData<String>()
    fun sendComment(pComment: PComment){
        viewModelScope.launch {
            try {
                sendSuccess.postValue(apiService.sendComment(pComment))
            } catch (e: Exception) {
                sendFail.postValue(e.message.toString())
            }
        }
    }
}